home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / PROGEDIT / 0748.ZIP / MSCCOMP < prev    next >
Text File  |  1987-07-04  |  3KB  |  90 lines

  1. /**********************************************************************/
  2. /* MSCCOMP - this file contains macros for automating the compile and */
  3. /*  error-search procedures under Microsoft 4.0. To compile the       */
  4. /*  current buffer, press ALT C. To search for errors, press CTRL N.  */
  5. /*                                                                    */
  6. /* Written by Marc Adler of MAGMA SYSTEMS.  January 1987              */
  7. /**********************************************************************/
  8.  
  9. #define ALT_C   174
  10. #define CTRL_N  14
  11.  
  12. #define NO      0
  13. #define YES     1
  14.  
  15. int reached_eof;
  16.  
  17. init()
  18. {
  19.   assign_key("compile",    ALT_C);
  20.   assign_key("next_error", CTRL_N);
  21. }
  22.  
  23. compile()
  24. {
  25.   string currfile, extension;
  26.   string errmsg;
  27.   int    i;
  28.  
  29.   errmsg = "Error - the file is not a C file. <Hit ENTER to continue>";
  30.   
  31.   currfile = filename();
  32.  
  33.   /* Make sure that the current buffer is a C file */
  34.   if ((i = index(currfile, ".")) > 0)           /* get the extension */
  35.   {
  36.     extension = substr(currfile, i+1, 3);
  37.     if (extension != "c" && extension != "C")   /* is it a C file?   */
  38.     {
  39.       get_tty_str(errmsg);                      /* NO!!! Error!!!    */
  40.       return;
  41.     }
  42.   }
  43.   else              /* the buffer has no extension, so it's an error */
  44.   {
  45.     get_tty_str(errmsg);
  46.     return;
  47.   }
  48.  
  49.   writefile(currfile);      /* save the current version & compile it */
  50.   os_command(sprintf("msc /AL /Zi /J %s; > errs", currfile));
  51.   next_error();             /* see if there are errors               */
  52. }
  53.  
  54. next_error()
  55. {
  56.   int id, old_id;
  57.   int n;
  58.   string cl, foo;
  59.  
  60.   old_id = currbuf();           /* save the id of the source buffer */
  61.  
  62.   if ((id = find_buffer("errs")) == 0)
  63.   {
  64.     id = create_buffer("errs");
  65.     reached_eof = NO;
  66.   }
  67.   id = setcurrbuf(id);
  68.  
  69.   /* Microsoft C Ver.4.0 puts out error messages in this format : */
  70.   /*      filename(line #) : messagetype error# message           */
  71.   if (reached_eof == NO && fsearch("([0-9][0-9]*) : ?*error") > 0)
  72.   {
  73.     n = atoi(substr(cl = currline(), currcol()+1, 5));  /* get line # */
  74.     gobol();                    /* move to the next error */
  75.     if (!down())
  76.       reached_eof = YES;
  77.     show_buffer(old_id);        /* go to the source buffer and */
  78.     goline(n);                  /*  move to the offending line */
  79.     message(cl);                /* display the error message   */
  80.     get_tty_char();             /* and let the user acknowledge*/
  81.   }
  82.  
  83.   else          /* Reached the end of the error file */
  84.   {
  85.     foo = get_tty_str("NO MORE ERRORS");
  86.     delete_buffer(id);          /* get rid of the error buffer */
  87.     show_buffer(old_id);        /* and set the current buffer  */
  88.   }
  89. }
  90.